package com.jslx.config.mvc;

import com.jslx.interceptorbase.RequestInterceptorBase;
import com.jslx.interceptorbase.loginInterceprotphone.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by ydw on 2017/7/22.
 */
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
    /**
     * 页面跳转的控制
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/toLogin").setViewName("login");
    }

    /**
     * 把拦截器的放入容器
     * @return
     */
    @Bean
    public RequestInterceptorBase requestInterceptorBase(){
        return new RequestInterceptorBase();
    }


    /**
     * 注册拦截器
     * @param registry
     */
    @Autowired
    LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(requestInterceptorBase());
        registry.addInterceptor(loginInterceptor);
    }
}
